﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BotonJXC.Entity
{
    public class PageModel<T>
        where T : BaseEntity
    {
        private int _totalCount;
        private int _pageSize = 10;

        public PageModel()
        { }

        /// <summary>
        /// 页面开始位置
        /// </summary>
        public int PageStart
        {
            get
            {
                return (PageNo - 1) * PageSize;
            }
        }
        /// <summary>
        /// 获取或设置当前页码
        /// </summary>
        public int PageNo { get; set; }
        /// <summary>
        /// 获取或设置每页显示数量
        /// </summary>
        public int PageSize
        {
            get
            {
                if (_pageSize < 1)
                    _pageSize = 10;
                return _pageSize;
            }
            set { _pageSize = value; }
        }
        /// <summary>
        /// 获取总页数
        /// </summary>
        public int PageCount
        {
            get
            {
                int pageCount = TotalCount % PageSize == 0 ? TotalCount / PageSize : TotalCount / PageSize + 1;
                return pageCount < 1 ? 1 : pageCount;
            }
        }
        /// <summary>
        /// 获取或设置总记录数
        /// </summary>
        public int TotalCount
        {
            get
            {
                return _totalCount;
            }
            set
            {
                _totalCount = value;
            }
        }

        public IList<T> Results { get; set; }
    }
}
